package com.hy.mydesktop.client.component.factory;

import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.Layout;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.hy.mydesktop.client.component.meta.AccordionPanelModelEnum;
import com.hy.mydesktop.client.component.meta.WindowModelEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.rpc.util.ComponentTypeEnumConverter;

/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-8-29；时间：下午03:55:18</li>
 * <li>类型名称：WindowFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class WindowFactory {

	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建Window控件</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午03:05:09</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	public static Window createWindow(GxtComponentMetaNodeModel gxtComponentMetaNodeModel){
		
		return configureWindow(gxtComponentMetaNodeModel);
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：对窗口的属性进行配置</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午03:56:36</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static Window configureWindow(GxtComponentMetaNodeModel gxtComponentMetaNodeModel){
		
		Window window=createDefaultWindow();
		
//		window = (Window)AbstractComponetFactory.configureAbstractComponet(window, gxtComponentMetaNodeModel);
		window = AbstractComponetFactory.configureAbstractComponet(window, gxtComponentMetaNodeModel);
		window = AbstractLayoutContainerComponetFactory.configureAbstractLayoutContainerComponet(window, gxtComponentMetaNodeModel);
		window= (Window)ContentPanelFactory.configureAttributesOfContentPanel(window, gxtComponentMetaNodeModel);

		//设置窗口的宽度
		
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.INITIALWIDTH.name().toLowerCase())!=null){
			//设置窗口的初始化宽度
			window.setInitialWidth((Integer)gxtComponentMetaNodeModel.get(WindowModelEnum.INITIALWIDTH.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.MINWIDTH.name().toLowerCase())!=null){
			//设置窗口的最小宽度
			window.setMinWidth((Integer)gxtComponentMetaNodeModel.get(WindowModelEnum.MINWIDTH.name().toLowerCase()));
		
		}
		
		//设置窗口的最小高度		
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.MINHIGHT.name().toLowerCase())!=null){
			//设置窗口的最小高度
			window.setMinHeight((Integer)gxtComponentMetaNodeModel.get(WindowModelEnum.MINHIGHT.name().toLowerCase()));
		
		}
		
		//设置窗口标题
		
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.MODAL.name().toLowerCase())!=null){
			//设置窗口是否为模式窗口
			window.setModal((Boolean)gxtComponentMetaNodeModel.get(WindowModelEnum.MODAL.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.RESIZABLE.name().toLowerCase())!=null){
			//设置窗口是否可以拖拽
			window.setResizable((Boolean)gxtComponentMetaNodeModel.get(WindowModelEnum.RESIZABLE.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.MAXMIZABLE.name().toLowerCase())!=null){
			//设置最大化按钮
			window.setMaximizable((Boolean)gxtComponentMetaNodeModel.get(WindowModelEnum.MAXMIZABLE.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.MINMIZABLE.name().toLowerCase())!=null){
			//设置最小化按钮
			window.setMinimizable((Boolean)gxtComponentMetaNodeModel.get(WindowModelEnum.MINMIZABLE.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.CLOSABLE.name().toLowerCase())!=null){
			//设置关闭按钮
			window.setClosable((Boolean)gxtComponentMetaNodeModel.get(WindowModelEnum.CLOSABLE.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.SCROLLMODE.name().toLowerCase())!=null){
			//设置滚动条
			window.setScrollMode((Scroll)gxtComponentMetaNodeModel.get(WindowModelEnum.SCROLLMODE.name().toLowerCase()));
		
		}
		
		
		if(gxtComponentMetaNodeModel.get(WindowModelEnum.TOPCOMPONENT.name().toLowerCase())!=null){
			//设置窗口的顶部组建
			window.setTopComponent((Component)gxtComponentMetaNodeModel.get(WindowModelEnum.TOPCOMPONENT.name().toLowerCase()));
		
		}
		
		return window;
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建默认的窗口</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午03:56:49</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	private static Window createDefaultWindow(){
		Window window=new Window();
		
		window.setSize(400, 300);
		window.setHeading("window");
		window.setFrame(true);
		window.setLayout(new FitLayout());
		
		return window;
	}
}
